/*
 * StrahlentherapieRunAction.cc
 *
 *  Created on: Nov 26, 2010
 *      Author: holger
 */

#include "StrahlentherapieRunAction.hh"
#include "StrahlentherapieRun.hh"

StrahlentherapieRunAction::StrahlentherapieRunAction()
{}

StrahlentherapieRunAction::~StrahlentherapieRunAction()
{}

G4Run* StrahlentherapieRunAction::GenerateRun()
{
	return (new StrahlentherapieRun);
}

void StrahlentherapieRunAction::BeginOfRunAction(const G4Run* aRun)
{}

void StrahlentherapieRunAction::EndOfRunAction(const G4Run* aRun)
{
	StrahlentherapieRun * theRun = (StrahlentherapieRun *)aRun;
	
	// Head
	std::map<G4int,G4double*>* energyHeadEvtMap = theRun->totalEnergyHead.GetMap();
	std::map<G4int,G4double*>* doseHeadEvtMap = theRun->totalDoseHead.GetMap();
	std::map<G4int,G4double*>::iterator itE = energyHeadEvtMap->begin();
	std::map<G4int,G4double*>::iterator itD = doseHeadEvtMap->begin();
	
	G4double totE = 0;
	for(; itE != energyHeadEvtMap->end(); itE++, itD++) {
		if(itE->first != itD->first) {
			G4cerr << "Achtung: Annahme das Energie- und Dosis-Zelle übereinstimmen nicht erfüllt." << G4endl;
		}
		totE += *(itE->second);
		G4cout << "Headbox\t" << itE->first << "\t" << *(itE->second) << "\t" << *(itD->second) << G4endl;
	}
	G4cout << "     Total energy deposition in head box:       " << totE / MeV << " (MeV)" << G4endl;

	// Detektorplatte
	std::map<G4int,G4double*>* energyDPEvtMap = theRun->totalEnergyDetectorPlate.GetMap();
	std::map<G4int,G4double*>::iterator itDP = energyDPEvtMap->begin();
	
	totE = 0;
	for(; itDP != energyDPEvtMap->end(); itDP++) {
		totE += *(itDP->second);
		G4cout << "DetectorPlate\t" << itDP->first << "\t" << *(itDP->second) << G4endl;
	}
	G4cout << "     Total energy deposition in detector plate: " << totE / MeV << " (MeV)" << G4endl;
}

